<div class="container">
    <h1 id="pkg-overview">package strings</h1>
    <p><code>import "strings"</code>
    </p><p>strings包实现了用于操作字符的简单函数。</p>
    
    
		
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
    
		
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    <h2 id="EqualFold">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#674" title="View Source">EqualFold</a> </h2>
    <pre class="funcdecl">func EqualFold(s, t <a href="builtin.htm#string">string</a>) <a href="builtin.htm#bool">bool</a></pre>
    <p>判断两个utf-8编码字符串（将unicode大写、小写、标题三种格式字符视为相同）是否相同。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-EqualFold">
            <div class="panel-heading" onclick="document.getElementById('ex-EqualFold').style.display = document.getElementById('ex-EqualFold').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-EqualFold">
                <div class="panel-body">
                    <pre>fmt.Println(strings.EqualFold("Go", "go"))</pre>
                    <p>Output:
                    </p><pre>true
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="HasPrefix">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#371" title="View Source">HasPrefix</a> </h2>
    <pre class="funcdecl">func HasPrefix(s, prefix <a href="builtin.htm#string">string</a>) <a href="builtin.htm#bool">bool</a></pre>
    <p>判断s是否有前缀字符串prefix。</p>
    <h2 id="HasSuffix">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#376" title="View Source">HasSuffix</a> </h2>
    <pre class="funcdecl">func HasSuffix(s, suffix <a href="builtin.htm#string">string</a>) <a href="builtin.htm#bool">bool</a></pre>
    <p>判断s是否有后缀字符串suffix。</p>
    <h2 id="Contains">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#112" title="View Source">Contains</a> </h2>
    <pre class="funcdecl">func Contains(s, substr <a href="builtin.htm#string">string</a>) <a href="builtin.htm#bool">bool</a></pre>
    <p>判断字符串s是否包含子串substr。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Contains">
            <div class="panel-heading" onclick="document.getElementById('ex-Contains').style.display = document.getElementById('ex-Contains').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Contains">
                <div class="panel-body">
                    <pre>fmt.Println(strings.Contains("seafood", "foo"))
fmt.Println(strings.Contains("seafood", "bar"))
fmt.Println(strings.Contains("seafood", ""))
fmt.Println(strings.Contains("", ""))</pre>
                    <p>Output:
                    </p><pre>true
false
true
true
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="ContainsRune">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#122" title="View Source">ContainsRune</a> </h2>
    <pre class="funcdecl">func ContainsRune(s <a href="builtin.htm#string">string</a>, r <a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#bool">bool</a></pre>
    <p>判断字符串s是否包含utf-8码值r。</p>
    <h2 id="ContainsAny">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#117" title="View Source">ContainsAny</a> </h2>
    <pre class="funcdecl">func ContainsAny(s, chars <a href="builtin.htm#string">string</a>) <a href="builtin.htm#bool">bool</a></pre>
    <p>判断字符串s是否包含字符串chars中的任一字符。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-ContainsAny">
            <div class="panel-heading" onclick="document.getElementById('ex-ContainsAny').style.display = document.getElementById('ex-ContainsAny').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-ContainsAny">
                <div class="panel-body">
                    <pre>fmt.Println(strings.ContainsAny("team", "i"))
fmt.Println(strings.ContainsAny("failure", "u &amp; i"))
fmt.Println(strings.ContainsAny("foo", ""))
fmt.Println(strings.ContainsAny("", ""))</pre>
                    <p>Output:
                    </p><pre>false
true
false
false
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Count">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#65" title="View Source">Count</a> </h2>
    <pre class="funcdecl">func Count(s, sep <a href="builtin.htm#string">string</a>) <a href="builtin.htm#int">int</a></pre>
    <p>返回字符串s中有几个不重复的sep子串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Count">
            <div class="panel-heading" onclick="document.getElementById('ex-Count').style.display = document.getElementById('ex-Count').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Count">
                <div class="panel-body">
                    <pre>fmt.Println(strings.Count("cheese", "e"))
fmt.Println(strings.Count("five", "")) <span class="com">// before &amp; after each rune</span></pre>
                    <p>Output:
                    </p><pre>3
5
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Index">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#127" title="View Source">Index</a> </h2>
    <pre class="funcdecl">func Index(s, sep <a href="builtin.htm#string">string</a>) <a href="builtin.htm#int">int</a></pre>
    <p>子串sep在字符串s中第一次出现的位置，不存在则返回-1。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Index">
            <div class="panel-heading" onclick="document.getElementById('ex-Index').style.display = document.getElementById('ex-Index').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Index">
                <div class="panel-body">
                    <pre>fmt.Println(strings.Index("chicken", "ken"))
fmt.Println(strings.Index("chicken", "dmr"))</pre>
                    <p>Output:
                    </p><pre>4
-1
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="IndexByte">func <a href="https://github.com/golang/go/blob/master/src/strings/strings_decl.go?name=release#8" title="View Source">IndexByte</a> </h2>
    <pre class="funcdecl">func IndexByte(s <a href="builtin.htm#string">string</a>, c <a href="builtin.htm#byte">byte</a>) <a href="builtin.htm#int">int</a></pre>
    <p>字符c在s中第一次出现的位置，不存在则返回-1。</p>
    <h2 id="IndexRune">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#190" title="View Source">IndexRune</a> </h2>
    <pre class="funcdecl">func IndexRune(s <a href="builtin.htm#string">string</a>, r <a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#int">int</a></pre>
    <p>unicode码值r在s中第一次出现的位置，不存在则返回-1。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-IndexRune">
            <div class="panel-heading" onclick="document.getElementById('ex-IndexRune').style.display = document.getElementById('ex-IndexRune').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-IndexRune">
                <div class="panel-body">
                    <pre>fmt.Println(strings.IndexRune("chicken", 'k'))
fmt.Println(strings.IndexRune("chicken", 'd'))</pre>
                    <p>Output:
                    </p><pre>4
-1
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="IndexAny">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#211" title="View Source">IndexAny</a> </h2>
    <pre class="funcdecl">func IndexAny(s, chars <a href="builtin.htm#string">string</a>) <a href="builtin.htm#int">int</a></pre>
    <p>字符串chars中的任一utf-8码值在s中第一次出现的位置，如果不存在或者chars为空字符串则返回-1。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-IndexAny">
            <div class="panel-heading" onclick="document.getElementById('ex-IndexAny').style.display = document.getElementById('ex-IndexAny').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-IndexAny">
                <div class="panel-body">
                    <pre>fmt.Println(strings.IndexAny("chicken", "aeiouy"))
fmt.Println(strings.IndexAny("crwth", "aeiouy"))</pre>
                    <p>Output:
                    </p><pre>2
-1
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="IndexFunc">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#537" title="View Source">IndexFunc</a> </h2>
    <pre class="funcdecl">func IndexFunc(s <a href="builtin.htm#string">string</a>, f func(<a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#bool">bool</a>) <a href="builtin.htm#int">int</a></pre>
    <p>s中第一个满足函数f的位置i（该处的utf-8码值r满足f(r)==true），不存在则返回-1。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-IndexFunc">
            <div class="panel-heading" onclick="document.getElementById('ex-IndexFunc').style.display = document.getElementById('ex-IndexFunc').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-IndexFunc">
                <div class="panel-body">
                    <pre>f := func(c rune) bool {
    return unicode.Is(unicode.Han, c)
}
fmt.Println(strings.IndexFunc("Hello, 世界", f))
fmt.Println(strings.IndexFunc("Hello, world", f))</pre>
                    <p>Output:
                    </p><pre>7
-1
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="LastIndex">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#164" title="View Source">LastIndex</a> </h2>
    <pre class="funcdecl">func LastIndex(s, sep <a href="builtin.htm#string">string</a>) <a href="builtin.htm#int">int</a></pre>
    <p>子串sep在字符串s中最后一次出现的位置，不存在则返回-1。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-LastIndex">
            <div class="panel-heading" onclick="document.getElementById('ex-LastIndex').style.display = document.getElementById('ex-LastIndex').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-LastIndex">
                <div class="panel-body">
                    <pre>fmt.Println(strings.Index("go gopher", "go"))
fmt.Println(strings.LastIndex("go gopher", "go"))
fmt.Println(strings.LastIndex("go gopher", "rodent"))</pre>
                    <p>Output:
                    </p><pre>0
3
-1
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="LastIndexAny">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#227" title="View Source">LastIndexAny</a> </h2>
    <pre class="funcdecl">func LastIndexAny(s, chars <a href="builtin.htm#string">string</a>) <a href="builtin.htm#int">int</a></pre>
    <p>字符串chars中的任一utf-8码值在s中最后一次出现的位置，如不存在或者chars为空字符串则返回-1。</p>
    <h2 id="LastIndexFunc">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#543" title="View Source">LastIndexFunc</a> </h2>
    <pre class="funcdecl">func LastIndexFunc(s <a href="builtin.htm#string">string</a>, f func(<a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#bool">bool</a>) <a href="builtin.htm#int">int</a></pre>
    <p>s中最后一个满足函数f的unicode码值的位置i，不存在则返回-1。</p>
    <h2 id="Title">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#489" title="View Source">Title</a> </h2>
    <pre class="funcdecl">func Title(s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p align="left">返回s中每个单词的首字母都改为标题格式的字符串拷贝。</p>
    <p align="left">BUG: Title用于划分单词的规则不能很好的处理Unicode标点符号。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Title">
            <div class="panel-heading" onclick="document.getElementById('ex-Title').style.display = document.getElementById('ex-Title').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Title">
                <div class="panel-body">
                    <pre>fmt.Println(strings.Title("her royal highness"))</pre>
                    <p>Output:
                    </p><pre>Her Royal Highness
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="ToLower">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#437" title="View Source">ToLower</a> </h2>
    <pre class="funcdecl">func ToLower(s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将所有字母都转为对应的小写版本的拷贝。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-ToLower">
            <div class="panel-heading" onclick="document.getElementById('ex-ToLower').style.display = document.getElementById('ex-ToLower').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-ToLower">
                <div class="panel-body">
                    <pre>fmt.Println(strings.ToLower("Gopher"))</pre>
                    <p>Output:
                    </p><pre>gopher
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="ToLowerSpecial">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#450" title="View Source">ToLowerSpecial</a> </h2>
    <pre class="funcdecl">func ToLowerSpecial(_case <a href="unicode.htm">unicode</a>.<a href="unicode.htm#SpecialCase">SpecialCase</a>, s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>使用_case规定的字符映射，返回将所有字母都转为对应的小写版本的拷贝。</p>
    <h2 id="ToUpper">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#434" title="View Source">ToUpper</a> </h2>
    <pre class="funcdecl">func ToUpper(s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将所有字母都转为对应的大写版本的拷贝。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-ToUpper">
            <div class="panel-heading" onclick="document.getElementById('ex-ToUpper').style.display = document.getElementById('ex-ToUpper').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-ToUpper">
                <div class="panel-body">
                    <pre>fmt.Println(strings.ToUpper("Gopher"))</pre>
                    <p>Output:
                    </p><pre>GOPHER
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="ToUpperSpecial">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#444" title="View Source">ToUpperSpecial</a> </h2>
    <pre class="funcdecl">func ToUpperSpecial(_case <a href="unicode.htm">unicode</a>.<a href="unicode.htm#SpecialCase">SpecialCase</a>, s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>使用_case规定的字符映射，返回将所有字母都转为对应的大写版本的拷贝。</p>
    <h2 id="ToTitle">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#440" title="View Source">ToTitle</a> </h2>
    <pre class="funcdecl">func ToTitle(s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将所有字母都转为对应的标题版本的拷贝。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-ToTitle">
            <div class="panel-heading" onclick="document.getElementById('ex-ToTitle').style.display = document.getElementById('ex-ToTitle').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-ToTitle">
                <div class="panel-body">
                    <pre>fmt.Println(strings.ToTitle("loud noises"))
fmt.Println(strings.ToTitle("хлеб"))</pre>
                    <p>Output:
                    </p><pre>LOUD NOISES
ХЛЕБ
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="ToTitleSpecial">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#456" title="View Source">ToTitleSpecial</a> </h2>
    <pre class="funcdecl">func ToTitleSpecial(_case <a href="unicode.htm">unicode</a>.<a href="unicode.htm#SpecialCase">SpecialCase</a>, s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>使用_case规定的字符映射，返回将所有字母都转为对应的标题版本的拷贝。</p>
    <h2 id="Repeat">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#424" title="View Source">Repeat</a> </h2>
    <pre class="funcdecl">func Repeat(s <a href="builtin.htm#string">string</a>, count <a href="builtin.htm#int">int</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回count个s串联的字符串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Repeat">
            <div class="panel-heading" onclick="document.getElementById('ex-Repeat').style.display = document.getElementById('ex-Repeat').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Repeat">
                <div class="panel-body">
                    <pre>fmt.Println("ba" + strings.Repeat("na", 2))</pre>
                    <p>Output:
                    </p><pre>banana
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Replace">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#638" title="View Source">Replace</a> </h2>
    <pre class="funcdecl">func Replace(s, old, new <a href="builtin.htm#string">string</a>, n <a href="builtin.htm#int">int</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将s中前n个不重叠old子串都替换为new的新字符串，如果n&lt;0会替换所有old子串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Replace">
            <div class="panel-heading" onclick="document.getElementById('ex-Replace').style.display = document.getElementById('ex-Replace').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Replace">
                <div class="panel-body">
                    <pre>fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2))
fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1))</pre>
                    <p>Output:
                    </p><pre>oinky oinky oink
moo moo moo
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Map">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#383" title="View Source">Map</a> </h2>
    <pre class="funcdecl">func Map(mapping func(<a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#rune">rune</a>, s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>将s的每一个unicode码值r都替换为mapping(r)，返回这些新码值组成的字符串拷贝。如果mapping返回一个负值，将会丢弃该码值而不会被替换。（返回值中对应位置将没有码值）</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Map">
            <div class="panel-heading" onclick="document.getElementById('ex-Map').style.display = document.getElementById('ex-Map').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Map">
                <div class="panel-body">
                    <pre>rot13 := func(r rune) rune {
    switch {
    case r &gt;= 'A' &amp;&amp; r &lt;= 'Z':
        return 'A' + (r-'A'+13)%26
    case r &gt;= 'a' &amp;&amp; r &lt;= 'z':
        return 'a' + (r-'a'+13)%26
    }
    return r
}
fmt.Println(strings.Map(rot13, "'Twas brillig and the slithy gopher..."))</pre>
                    <p>Output:
                    </p><pre>'Gjnf oevyyvt naq gur fyvgul tbcure...
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Trim">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#586" title="View Source">Trim</a> </h2>
    <pre class="funcdecl">func Trim(s <a href="builtin.htm#string">string</a>, cutset <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将s前后端所有cutset包含的utf-8码值都去掉的字符串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Trim">
            <div class="panel-heading" onclick="document.getElementById('ex-Trim').style.display = document.getElementById('ex-Trim').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Trim">
                <div class="panel-body">
                    <pre>fmt.Printf("[%q]", strings.Trim(" !!! Achtung! Achtung! !!! ", "! "))</pre>
                    <p>Output:
                    </p><pre>["Achtung! Achtung"]
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="TrimSpace">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#613" title="View Source">TrimSpace</a> </h2>
    <pre class="funcdecl">func TrimSpace(s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将s前后端所有空白（unicode.IsSpace指定）都去掉的字符串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-TrimSpace">
            <div class="panel-heading" onclick="document.getElementById('ex-TrimSpace').style.display = document.getElementById('ex-TrimSpace').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-TrimSpace">
                <div class="panel-body">
                    <pre>fmt.Println(strings.TrimSpace(" \t\n a lone gopher \n\t\r\n"))</pre>
                    <p>Output:
                    </p><pre>a lone gopher
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="TrimFunc">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#531" title="View Source">TrimFunc</a> </h2>
    <pre class="funcdecl">func TrimFunc(s <a href="builtin.htm#string">string</a>, f func(<a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#bool">bool</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将s前后端所有满足f的unicode码值都去掉的字符串。</p>
    <h2 id="TrimLeft">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#595" title="View Source">TrimLeft</a> </h2>
    <pre class="funcdecl">func TrimLeft(s <a href="builtin.htm#string">string</a>, cutset <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将s前端所有cutset包含的utf-8码值都去掉的字符串。</p>
    <h2 id="TrimLeftFunc">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#508" title="View Source">TrimLeftFunc</a> </h2>
    <pre class="funcdecl">func TrimLeftFunc(s <a href="builtin.htm#string">string</a>, f func(<a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#bool">bool</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将s前端所有满足f的unicode码值都去掉的字符串。</p>
    <h2 id="TrimPrefix">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#619" title="View Source">TrimPrefix</a> </h2>
    <pre class="funcdecl">func TrimPrefix(s, prefix <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回去除s可能的前缀prefix的字符串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-TrimPrefix">
            <div class="panel-heading" onclick="document.getElementById('ex-TrimPrefix').style.display = document.getElementById('ex-TrimPrefix').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-TrimPrefix">
                <div class="panel-body">
                    <pre>var s = "Goodbye,, world!"
s = strings.TrimPrefix(s, "Goodbye,")
s = strings.TrimPrefix(s, "Howdy,")
fmt.Print("Hello" + s)</pre>
                    <p>Output:
                    </p><pre>Hello, world!
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="TrimRight">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#604" title="View Source">TrimRight</a> </h2>
    <pre class="funcdecl">func TrimRight(s <a href="builtin.htm#string">string</a>, cutset <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将s后端所有cutset包含的utf-8码值都去掉的字符串。</p>
    <h2 id="TrimRightFunc">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#518" title="View Source">TrimRightFunc</a> </h2>
    <pre class="funcdecl">func TrimRightFunc(s <a href="builtin.htm#string">string</a>, f func(<a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#bool">bool</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回将s后端所有满足f的unicode码值都去掉的字符串。</p>
    <h2 id="TrimSuffix">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#628" title="View Source">TrimSuffix</a> </h2>
    <pre class="funcdecl">func TrimSuffix(s, suffix <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>返回去除s可能的后缀suffix的字符串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-TrimSuffix">
            <div class="panel-heading" onclick="document.getElementById('ex-TrimSuffix').style.display = document.getElementById('ex-TrimSuffix').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-TrimSuffix">
                <div class="panel-body">
                    <pre>var s = "Hello, goodbye, etc!"
s = strings.TrimSuffix(s, "goodbye, etc!")
s = strings.TrimSuffix(s, "planet")
fmt.Print(s, "world!")</pre>
                    <p>Output:
                    </p><pre>Hello, world!
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Fields">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#307" title="View Source">Fields</a> </h2>
    <pre class="funcdecl">func Fields(s <a href="builtin.htm#string">string</a>) []<a href="builtin.htm#string">string</a></pre>
    <p>返回将字符串按照空白（unicode.IsSpace确定，可以是一到多个连续的空白字符）分割的多个字符串。如果字符串全部是空白或者是空字符串的话，会返回空切片。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Fields">
            <div class="panel-heading" onclick="document.getElementById('ex-Fields').style.display = document.getElementById('ex-Fields').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Fields">
                <div class="panel-body">
                    <pre>fmt.Printf("Fields are: %q", strings.Fields("  foo bar  baz   "))</pre>
                    <p>Output:
                    </p><pre>Fields are: ["foo" "bar" "baz"]
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="FieldsFunc">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#314" title="View Source">FieldsFunc</a> </h2>
    <pre class="funcdecl">func FieldsFunc(s <a href="builtin.htm#string">string</a>, f func(<a href="builtin.htm#rune">rune</a>) <a href="builtin.htm#bool">bool</a>) []<a href="builtin.htm#string">string</a></pre>
    <p>类似Fields，但使用函数f来确定分割符（满足f的unicode码值）。如果字符串全部是分隔符或者是空字符串的话，会返回空切片。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-FieldsFunc">
            <div class="panel-heading" onclick="document.getElementById('ex-FieldsFunc').style.display = document.getElementById('ex-FieldsFunc').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-FieldsFunc">
                <div class="panel-body">
                    <pre>f := func(c rune) bool {
    return !unicode.IsLetter(c) &amp;&amp; !unicode.IsNumber(c)
}
fmt.Printf("Fields are: %q", strings.FieldsFunc("  foo1;bar2,baz3...", f))</pre>
                    <p>Output:
                    </p><pre>Fields are: ["foo1" "bar2" "baz3"]
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Split">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#294" title="View Source">Split</a> </h2>
    <pre class="funcdecl">func Split(s, sep <a href="builtin.htm#string">string</a>) []<a href="builtin.htm#string">string</a></pre>
    <p>用去掉s中出现的sep的方式进行分割，会分割到结尾，并返回生成的所有片段组成的切片（每一个sep都会进行一次切割，即使两个sep相邻，也会进行两次切割）。如果sep为空字符，Split会将s切分成每一个unicode码值一个字符串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Split">
            <div class="panel-heading" onclick="document.getElementById('ex-Split').style.display = document.getElementById('ex-Split').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Split">
                <div class="panel-body">
                    <pre>fmt.Printf("%q\n", strings.Split("a,b,c", ","))
fmt.Printf("%q\n", strings.Split("a man a plan a canal panama", "a "))
fmt.Printf("%q\n", strings.Split(" xyz ", ""))
fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))</pre>
                    <p>Output:
                    </p><pre>["a" "b" "c"]
["" "man " "plan " "canal panama"]
[" " "x" "y" "z" " "]
[""]
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="SplitN">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#277" title="View Source">SplitN</a> </h2>
    <pre class="funcdecl">func SplitN(s, sep <a href="builtin.htm#string">string</a>, n <a href="builtin.htm#int">int</a>) []<a href="builtin.htm#string">string</a></pre>
    <p>用去掉s中出现的sep的方式进行分割，会分割到结尾，并返回生成的所有片段组成的切片（每一个sep都会进行一次切割，即使两个sep相邻，也会进行两次切割）。如果sep为空字符，Split会将s切分成每一个unicode码值一个字符串。参数n决定返回的切片的数目：</p>
    <pre>n &gt; 0 : 返回的切片最多n个子字符串；最后一个子字符串包含未进行切割的部分。
n == 0: 返回nil
n &lt; 0 : 返回所有的子字符串组成的切片
</pre>
    <div class="panel-group">
        <div class="panel panel-default" id="example-SplitN">
            <div class="panel-heading" onclick="document.getElementById('ex-SplitN').style.display = document.getElementById('ex-SplitN').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-SplitN">
                <div class="panel-body">
                    <pre>fmt.Printf("%q\n", strings.SplitN("a,b,c", ",", 2))
z := strings.SplitN("a,b,c", ",", 0)
fmt.Printf("%q (nil = %v)\n", z, z == nil)</pre>
                    <p>Output:
                    </p><pre>["a" "b,c"]
[] (nil = true)
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="SplitAfter">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#300" title="View Source">SplitAfter</a> </h2>
    <pre class="funcdecl">func SplitAfter(s, sep <a href="builtin.htm#string">string</a>) []<a href="builtin.htm#string">string</a></pre>
    <p>用从s中出现的sep后面切断的方式进行分割，会分割到结尾，并返回生成的所有片段组成的切片（每一个sep都会进行一次切割，即使两个sep相邻，也会进行两次切割）。如果sep为空字符，Split会将s切分成每一个unicode码值一个字符串。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-SplitAfter">
            <div class="panel-heading" onclick="document.getElementById('ex-SplitAfter').style.display = document.getElementById('ex-SplitAfter').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-SplitAfter">
                <div class="panel-body">
                    <pre>fmt.Printf("%q\n", strings.SplitAfter("a,b,c", ","))</pre>
                    <p>Output:
                    </p><pre>["a," "b," "c"]
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="SplitAfterN">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#286" title="View Source">SplitAfterN</a> </h2>
    <pre class="funcdecl">func SplitAfterN(s, sep <a href="builtin.htm#string">string</a>, n <a href="builtin.htm#int">int</a>) []<a href="builtin.htm#string">string</a></pre>
    <p>用从s中出现的sep后面切断的方式进行分割，会分割到结尾，并返回生成的所有片段组成的切片（每一个sep都会进行一次切割，即使两个sep相邻，也会进行两次切割）。如果sep为空字符，Split会将s切分成每一个unicode码值一个字符串。参数n决定返回的切片的数目：</p>
    <pre>n &gt; 0 : 返回的切片最多n个子字符串；最后一个子字符串包含未进行切割的部分。
n == 0: 返回nil
n &lt; 0 : 返回所有的子字符串组成的切
</pre>
    <div class="panel-group">
        <div class="panel panel-default" id="example-SplitAfterN">
            <div class="panel-heading" onclick="document.getElementById('ex-SplitAfterN').style.display = document.getElementById('ex-SplitAfterN').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-SplitAfterN">
                <div class="panel-body">
                    <pre>fmt.Printf("%q\n", strings.SplitAfterN("a,b,c", ",", 2))</pre>
                    <p>Output:
                    </p><pre>["a," "b,c"]
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Join">func <a href="https://github.com/golang/go/blob/master/src/strings/strings.go?name=release#349" title="View Source">Join</a> </h2>
    <pre class="funcdecl">func Join(a []<a href="builtin.htm#string">string</a>, sep <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>将一系列字符串连接为一个字符串，之间用sep来分隔。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-Join">
            <div class="panel-heading" onclick="document.getElementById('ex-Join').style.display = document.getElementById('ex-Join').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-Join">
                <div class="panel-body">
                    <pre>s := []string{"foo", "bar", "baz"}
fmt.Println(strings.Join(s, ", "))</pre>
                    <p>Output:
                    </p><pre>foo, bar, baz
</pre>
                </div>
            </div>
        </div>
    </div>
    <h2 id="Reader">type <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#16" title="View Source">Reader</a> </h2>
    <pre>type Reader struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>Reader类型通过从一个字符串读取数据，实现了io.Reader、io.Seeker、io.ReaderAt、io.WriterTo、io.ByteScanner、io.RuneScanner接口。</p>
    <h3 id="NewReader">func <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#144" title="View Source">NewReader</a> </h3>
    <pre class="funcdecl">func NewReader(s <a href="builtin.htm#string">string</a>) *<a href="#Reader">Reader</a></pre>
    <p>NewReader创建一个从s读取数据的Reader。本函数类似bytes.NewBufferString，但是更有效率，且为只读的。</p>
    <h3 id="Reader.Len">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#24" title="View Source">Len</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) Len() <a href="builtin.htm#int">int</a></pre>
    <p>Len返回r包含的字符串还没有被读取的部分。</p>
    <h3 id="Reader.Read">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#31" title="View Source">Read</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) Read(b []<a href="builtin.htm#byte">byte</a>) (n <a href="builtin.htm#int">int</a>, err <a href="builtin.htm#error">error</a>)</pre>
    <h3 id="Reader.ReadByte">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#59" title="View Source">ReadByte</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadByte() (b <a href="builtin.htm#byte">byte</a>, err <a href="builtin.htm#error">error</a>)</pre>
    <h3 id="Reader.UnreadByte">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#69" title="View Source">UnreadByte</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) UnreadByte() <a href="builtin.htm#error">error</a></pre>
    <h3 id="Reader.ReadRune">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#78" title="View Source">ReadRune</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadRune() (ch <a href="builtin.htm#rune">rune</a>, size <a href="builtin.htm#int">int</a>, err <a href="builtin.htm#error">error</a>)</pre>
    <h3 id="Reader.UnreadRune">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#93" title="View Source">UnreadRune</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) UnreadRune() <a href="builtin.htm#error">error</a></pre>
    <h3 id="Reader.Seek">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#103" title="View Source">Seek</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) Seek(offset <a href="builtin.htm#int64">int64</a>, whence <a href="builtin.htm#int">int</a>) (<a href="builtin.htm#int64">int64</a>, <a href="builtin.htm#error">error</a>)</pre>
    <p>Seek实现了io.Seeker接口。</p>
    <h3 id="Reader.ReadAt">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#44" title="View Source">ReadAt</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) ReadAt(b []<a href="builtin.htm#byte">byte</a>, off <a href="builtin.htm#int64">int64</a>) (n <a href="builtin.htm#int">int</a>, err <a href="builtin.htm#error">error</a>)</pre>
    <h3 id="Reader.WriteTo">func (*Reader) <a href="https://github.com/golang/go/blob/master/src/strings/reader.go?name=release#124" title="View Source">WriteTo</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Reader">Reader</a>) WriteTo(w <a href="io.htm">io</a>.<a href="io.htm#Writer">Writer</a>) (n <a href="builtin.htm#int64">int64</a>, err <a href="builtin.htm#error">error</a>)</pre>
    <p>WriteTo实现了io.WriterTo接口。</p>
    <h2 id="Replacer">type <a href="https://github.com/golang/go/blob/master/src/strings/replace.go?name=release#10" title="View Source">Replacer</a> </h2>
    <pre>type Replacer struct {
    <span class="com">// 内含隐藏或非导出字段</span>
}</pre>
    <p>Replacer类型进行一系列字符串的替换。</p>
    <h3 id="NewReplacer">func <a href="https://github.com/golang/go/blob/master/src/strings/replace.go?name=release#31" title="View Source">NewReplacer</a> </h3>
    <pre class="funcdecl">func NewReplacer(oldnew ...<a href="builtin.htm#string">string</a>) *<a href="#Replacer">Replacer</a></pre>
    <p>使用提供的多组old、new字符串对创建并返回一个*Replacer。替换是依次进行的，匹配时不会重叠。</p>
    <div class="panel-group">
        <div class="panel panel-default" id="example-NewReplacer">
            <div class="panel-heading" onclick="document.getElementById('ex-NewReplacer').style.display = document.getElementById('ex-NewReplacer').style.display=='none'?'block':'none';">Example</div>
            <div class="panel-collapse collapse" id="ex-NewReplacer">
                <div class="panel-body">
                    <pre>r := strings.NewReplacer("&lt;", "&amp;lt;", "&gt;", "&amp;gt;")
fmt.Println(r.Replace("This is &lt;b&gt;HTML&lt;/b&gt;!"))</pre>
                    <p>Output:
                    </p><pre>This is &amp;lt;b&amp;gt;HTML&amp;lt;/b&amp;gt;!
</pre>
                </div>
            </div>
        </div>
    </div>
    <h3 id="Replacer.Replace">func (*Replacer) <a href="https://github.com/golang/go/blob/master/src/strings/replace.go?name=release#78" title="View Source">Replace</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Replacer">Replacer</a>) Replace(s <a href="builtin.htm#string">string</a>) <a href="builtin.htm#string">string</a></pre>
    <p>Replace返回s的所有替换进行完后的拷贝。</p>
    <h3 id="Replacer.WriteString">func (*Replacer) <a href="https://github.com/golang/go/blob/master/src/strings/replace.go?name=release#83" title="View Source">WriteString</a> </h3>
    <pre class="funcdecl">func (r *<a href="#Replacer">Replacer</a>) WriteString(w <a href="io.htm">io</a>.<a href="io.htm#Writer">Writer</a>, s <a href="builtin.htm#string">string</a>) (n <a href="builtin.htm#int">int</a>, err <a href="builtin.htm#error">error</a>)</pre>
    <p>WriteString向w中写入s的所有替换进行完后的拷贝。</p>
</div>